home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / ADD.CPP next >
C/C++ Source or Header  |  1994-12-13  |  6KB  |  255 lines

  1. // ADD.CPP                                     1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. /*********************************************************************/
  11. /* Define Statements */
  12. /*********************/
  13.  
  14. #define PROGRAM "ADD"    // Name of module
  15.  
  16. /*********************************************************************/
  17.  
  18. typedef struct
  19. {
  20.     char process_one;
  21.     char default_type;
  22.     char default_ext[5];
  23. } ADD_INFO;
  24.  
  25. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  26. static void add_one(AU *au, char *file_name, PACKAGE *package)
  27. {
  28.     char string[FLENGTH];     /* build the dos commands in the string */
  29.     int  did_rename;
  30.  
  31.     au_printf(au, "@?6Adding @?B%s @?6to @?1%s@?H\n", au->partial, file_name);
  32.  
  33.     if (package->arc[0] == '\0')
  34.     {
  35.         au_printf_error(au, "No archiving method specified for %s", file_name);
  36.         press_any_key(au);
  37.         return;
  38.     }
  39.  
  40.     did_rename = rename_strict(au, package, au->source_directory, file_name);
  41.  
  42.     au->number_processed++;
  43.     substitute_macros(string, package->arc, NULL,
  44.          au->unarc_paths == ON ? package->arc_path : package->arc_no_path,
  45.          NULL, file_name);
  46.  
  47.     strcat(string," ");
  48.     strcat(string, au->partial);
  49.  
  50.     if (!au->simulate)
  51.     {
  52.         execute(au, string, au->output, NULL, package->memoryNeeded);
  53.  
  54.         if (did_rename)
  55.             rename_strict_back(au->source_directory, file_name);
  56.  
  57.         fix_flist(au, file_name, file_name);
  58.     }
  59.     return;
  60. }
  61. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  62. static int add_func(AU *au, char *file_name)
  63. {
  64.     ARC_HANDLE arc_handle;
  65.     struct ftime ftime_hold;
  66.  
  67.     check_for_key();
  68.  
  69.     arc_handle.init(au, file_name);
  70.     arc_handle.get_time(&ftime_hold);
  71.     arc_handle.deinit(au);
  72.  
  73.     if (arc_handle.type > 0)
  74.     {
  75.         add_one(au, file_name, &au->package[arc_handle.type]);
  76.         if (au->date_retain == ON)
  77.             set_file_time(au, file_name, &ftime_hold);
  78.     }
  79.     return 0;
  80. }
  81. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  82. static void ReadCFGInfo(AU *au, CFG_HANDLE *cfg_handle)
  83. {
  84.     char string[200],
  85.          string2[200],
  86.          string3[200];
  87.     ADD_INFO *in = (ADD_INFO *)au->info;
  88.  
  89.     for(EVER)
  90.     {
  91.         if (cfg_handle->read_line(au, string)==EOF)
  92.             break;
  93.  
  94.         split_string(string, string2);
  95.         split_string(string, string3);
  96.  
  97.         if (string2[0] == '\0')
  98.             continue;
  99.  
  100.         strcpy(au->curOpt, string2);
  101.         au->curVal = string3;
  102.         switch (toupper(string2[1]) << 8 | toupper(string2[0]))
  103.         {
  104.             case 'BE':                                          // Begin
  105.                 return;
  106.             case 'DE':                                          // Default type
  107.                 if (isdigit(string[0]))
  108.                     in->default_type = atoi(string);
  109.                 else
  110.                     safe_string_copy(in->default_ext, string3, 5, FALSE);
  111.                 break;
  112.             case 'PA':                                          // Paths
  113.                 au->unarc_paths = get_value(au, OFF | ON);
  114.                 break;
  115.             default:
  116.                 cfg_handle->invalid_option(au, string2);
  117.         }
  118.     }
  119. }
  120. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  121. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  122.                             PARSE_TYPE type)
  123. {
  124.     ADD_INFO *in = (ADD_INFO *)au->info;
  125.  
  126.     switch (type)
  127.     {
  128.     case PARSE_PARAM_OPTION:
  129.         switch (option)
  130.         {
  131.         case 'P':
  132.             if (toupper(*cur_argv) == 'A')
  133.             {
  134.                 strcpy(au->curOpt, "-PA");
  135.                 au->curVal = cur_argv+1;
  136.                 au->unarc_paths = get_value(au, OFF | ON);
  137.             }
  138.             break;
  139.         case 'D':
  140.             au->date_retain = get_value(au, OFF | ON);
  141.             break;
  142.         case '?':
  143.             au_syntax_message(au, "Add");
  144.             au_printf(au,
  145.                 "[@?3options@?H] @?1Archive(s) @?Badd_filespec(s)@?H\n\n");
  146.             au_param_heading(au);
  147.             au_printf(au,
  148.                 "@?3-PA@?Hon|off        include file PAths when adding files\n"
  149.                 "@?3-D@?Hon|off         Date retain\n");
  150.             exit(0);
  151.         default:
  152.             au_invalid_option(au, PROGRAM, option);
  153.         }
  154.         return TRUE;
  155.     case PARSE_FILESPEC:
  156.         if (au->process_list.head == NULL)
  157.         {
  158.             au->process_list.add(cur_argv);
  159.             if (strchr(cur_argv, '*') == NULL &&
  160.                 strchr(cur_argv, '?') == NULL)
  161.             {
  162.                 in->process_one = TRUE;
  163.             }
  164.         }
  165.         else
  166.         {
  167.             strcat(au->partial, cur_argv);
  168.             strcat(au->partial, " ");
  169.         }
  170.         return TRUE;
  171.     case PARSE_POST_CHECK:
  172.         if (au->process_list.head == NULL)
  173.         {
  174.             au_printf_error(au, "No Archive file specified");
  175.             exit(0);
  176.         }
  177.         if (au->partial[0] == '\0')
  178.             strcpy(au->partial, "*.*");
  179.  
  180.         /* Must delay search until whole .cfg is parsed */
  181.         if (in->default_ext[0] != '\0')
  182.             in->default_type = find_ext(au, in->default_ext);
  183.         return TRUE;
  184.     }
  185.     return FALSE;
  186. }
  187. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  188. int main_add(AU *au, int argc, char *argv[])
  189. {
  190.     char string[FLENGTH];
  191.     ADD_INFO *in;
  192.  
  193.     in = new ADD_INFO;
  194.     memset(in, '\0', sizeof(ADD_INFO));
  195.     au->info = in;
  196.     in->default_type = -1;
  197.  
  198.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, ReadCFGInfo);
  199.  
  200.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  201.  
  202.  
  203.     if (!in->process_one)
  204.         process_files(au, add_func);
  205.     else
  206.     {
  207.         char *ptr;
  208.         char type;
  209.  
  210.         ptr = strchr(au->process_list.head->data, '.');
  211.  
  212.         build_fname(string, au->source_directory, au->process_list.head->data);
  213.  
  214.         if (access(string, 0x00) == 0)
  215.         {
  216.             process_files(au, add_func);
  217.             if (au->number_processed == 0)
  218.             {
  219.                 au_printf_error(au, "\nCan not add to a non archive");
  220.                 exit(1);
  221.             }
  222.         }
  223.         else if (ptr == NULL)
  224.         {
  225.             if (in->default_type == -1)
  226.             {
  227.                 au_printf_error(au, "\nNo Recognizable Default Type specified");
  228.                 exit(1);
  229.             }
  230.             add_one(au, au->process_list.head->data, &au->package[in->default_type]);
  231.         }
  232.         else
  233.         {
  234.             if ((type = find_ext(au, ptr+1)) == -1)
  235.             {
  236.                 if (in->default_type != -1)
  237.                     type = in->default_type;
  238.             }
  239.  
  240.             if (type == -1)
  241.             {
  242.                 au_printf_error(au, "\nNo Recognizable Default Type specified");
  243.                 exit(1);
  244.             }
  245.             add_one(au, au->process_list.head->data, &au->package[type]);
  246.         }
  247.  
  248.     }
  249.     if (!au->no_extra)
  250.         au_printf_c(au, 15, "\n\nFiles Processed = %d\n", au->number_processed);
  251.  
  252.     return (0);
  253. }
  254.  
  255.